package TreeDayShuZu;

import org.junit.Test;

public class Dome06 {
    public static void main(String[] args) {
        //数组的扩容,并加入三个数
        int[] oldarr=new int[]{1,2,3,4,5};
        int[] newarr=new int[oldarr.length+3];
        //给数组进行赋值
        for (int i = 0; i < oldarr.length; i++) {
            newarr[i]=oldarr[i];
        }
        newarr[oldarr.length]=10;
        newarr[oldarr.length+1]=20;
        newarr[oldarr.length+2]=30;
        //新数组的值赋给旧数组
        oldarr=newarr;
        System.out.println("新增之后的数组");
        for (int i = 0; i < oldarr.length; i++) {
            System.out.print(oldarr[i]+" ");
        }
    }
    //数组的缩容
    @Test
    public void test01(){
        int[] arr={1,2,3,4,5,6,7};
        //删除数组中索引为4的数
        int dellndex=4;
        for (int i =dellndex ; i < arr.length-1; i++) {
            arr[i]=arr[i+1];
        }
        arr[arr.length-1]=0;
        //缩容之后的结果是
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }
}